<template>
  <a-spin :spinning="confirmLoading" style="background: #fff">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="8" :hidden="true">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle" >
              <a-input :max-length="255" v-model="model.bpmBizTitle" placeholder="请输入流程名称" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidNo">
              <a-input v-model="model.bidResultNo" placeholder="请输入单据编号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                placeholder="请选择日期"
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
                disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <!-- <select-user-by-dep
                v-model="model.proposer"
                disabled/> -->
                <select-user-by-dep  :multi="false" v-model="model.proposer" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart v-model="model.proposerDeptId" disabled/>
            </a-form-model-item>
          </a-col>
          <a-divider>基本信息</a-divider>
          <a-col :span="8">
            <a-form-model-item label="关联投标档案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderId">
              <!--迭代11 投标档案弹窗-->
              <!-- <j-popup
                  placeholder="请选择投标档案"
                  v-model="model.tenderFinalCode"
                  field="tenderFinalId"
                  dest-fields="tenderFinalId,prepareProjectId,id"
                  org-fields ="tender_code,prepare_project_id,id"
                  code="erp_omc_tender_final_model"
                  @input="chooseTenderChange"
                  disabled
                /> -->
                <!-- 投标档案弹窗 -->
              <select-omc-project-tender-input v-model="model.tenderId" @back="tenderFinalChange" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input  v-model="model.projectName" placeholder="请输入项目名称" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="undertaker">
              <select-user-by-dep
                disabled
                v-model="model.undertaker"
                placeholder="请选择项目承接人"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <j-dict-select-tag
                disabled
                type="list"
                v-model="model.year"
                dictCode="yjgsnd"
                placeholder="请选择业绩归属年度"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item label="项目地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-form-model-item style="display: inline-block; width: 46%" prop="projectAddress">
                <AddressChoice  v-model="model.projectAddress" disabled></AddressChoice>
              </a-form-model-item>
              <a-form-model-item
                style="display: inline-block; width: 46%; margin-left: 45px"
                prop="detailedAddress">
                <a-input  v-model="model.detailedAddress" placeholder="请输入项目详细地址" disabled></a-input>
              </a-form-model-item>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessTeam">
              <select-team-input
                disabled
                v-model="model.businessTeam"
                :tdlx="1"/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="开标时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidOpeningData">
              <j-date
                showTime
                disabled
                v-model="model.bidOpeningData"
                style="width: 100%"
                date-format="YYYY-MM-DD HH:mm:ss"
                placeholder="请选择开标时间"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="biddingMethod">
              <j-dict-select-tag
                disabled
                type="list"
                v-model="model.biddingMethod"
                dictCode="bidding_method"
                placeholder="请选择招标方式"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="业主单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerUnit">
              <select-customer-input  v-model="model.ownerUnit" @change="ownerUnitChange" placeholder="请选择业主单位" disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="业主联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerLinkman">
              <j-dict-select-tag
                disabled
                type="list"
                v-model="model.ownerLinkman"
                :dictCode="customer_contacts"
                placeholder="请选择业主联系人"
                @change="contactsChange"
                :triggerChange="true"/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="业主联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownerTel">
              <a-input  v-model="model.ownerTel" placeholder="请输入业主联系方式" disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="招标代理机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAgent">
              <a-input  v-model="model.tenderAgent" placeholder="请输入招标代理机构" disabled></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="招标代理联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAgentLinkman">
              <a-input  v-model="model.tenderAgentLinkman" placeholder="请输入招标代理联系人" disabled></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="招标代理联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAgentTel">
              <a-input  v-model="model.tenderAgentTel" placeholder="请输入招标代理联系方式" disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="项目公示信息" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectPublicity">
              <a-textarea  :max-length="500" v-model="model.projectPublicity" rows="4" placeholder="请输入项目公示信息" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投标内容概要" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderContent">
              <a-textarea  v-model="model.tenderContent" rows="4" placeholder="请输入投标内容概要" disabled/>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="招标文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderFile">
              <j-upload v-if="!formDisabled"  v-model="model.tenderFile" disabled></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.tenderFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col>

          <a-col :span="8">
            <a-form-model-item label="招标控制价(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="controlPrice">
              <a-input-number
                :precision="2"
                disabled
                v-model="model.controlPrice"
                placeholder="请输入招标控制价"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="招标代理费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="agentFee">
              <a-input-number
                :precision="2"
                disabled
                v-model="model.agentFee"
                placeholder="请输入招标代理费"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="履约保证金形式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bailType">
              <j-dict-select-tag
                disabled
                type="list"
                v-model="model.bailType"
                dictCode="bail_type"
                placeholder="请选择履约保证金形式"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="履约保证金(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bail">
              <a-input-number
                :precision="2"
                disabled
                v-model="model.bail"
                placeholder="请输入履约保证金"
                :min="0"
                :max="999999999"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="履约保证金退还日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bailReturnData">
              <j-date
                disabled
                placeholder="请选择履约保证金退还日期"
                v-model="model.bailReturnData"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="归档资料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archivesFile">
              <j-upload v-if="!formDisabled"  v-model="model.archivesFile" disabled></j-upload>
              <a-button v-else icon="download" @click="viewFile(model.archivesFile)">文件列表</a-button>
            </a-form-model-item>
          </a-col>

          <a-divider>投标单位信息（内部）</a-divider>
          <a-col :span="8">
            <a-form-model-item label="投标单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderUnit">
              <!--              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.tenderUnit" dictCode="erp_company_files,file_name,id,del_flag=0 and audit_status=2" placeholder="请选择投标单位"/>-->
              <!--              <j-select-company :disabled="disabled" v-model="model.tenderUnit"/>-->
              <select-Company-input :disabled="formDisabled" v-model="model.tenderUnit"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectLeading">
              <a-input :disabled=formDisabled v-model="model.projectLeading" placeholder="请输入项目负责人"></a-input>
              <!-- <select-user-by-dep
                :disabled="formDisabled"
                v-model="model.projectLeading"/> -->
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="投标金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenderAmount">
              <a-input :disabled="formDisabled" v-model="model.tenderAmount" placeholder="请输入投标金额"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="中标结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bidResult">
              <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.bidResult" dictCode="bid_result"
                placeholder="请选择中标结果"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="难度系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="complexCoefficient">
              <a-input   v-model="model.complexCoefficient" placeholder="请输入难度系数"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="成果系数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="resultCoefficient">
              <a-input   v-model="model.resultCoefficient" placeholder="请输入成果系数"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instruction">
              <a-textarea :disabled="formDisabled" v-model="model.instruction" rows="4" placeholder="请输入说明"/>
            </a-form-model-item>
          </a-col>
          <a-divider>投标单位信息（外部）</a-divider>

          <a-col :span="24">
            <div style="margin-bottom: 6px;margin-top: 6px">
              <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>
            </div>
            <a-table
              ref="table"
              size="middle"
              rowKey="id"
              :scroll="{x:'130%'}"
              :loading="loading"
              :columns="columns"
              :pagination="false"
              :data-source="dataSource">
<!--              <span slot="action" slot-scope="text, record">-->
<!--                <template v-if="formDisabledEdit">-->
<!--                  <a @click="handleEdit(record)">编辑</a>-->
<!--                  <a-divider type="vertical"/>-->
<!--                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                    <a>删除</a>-->
<!--                  </a-popconfirm>-->
<!--                </template>-->
<!--              </span>-->
            </a-table>
          </a-col>
          <!-- <a-col :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col> -->
        </a-row>
      </a-form-model>
      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
      <view-file-modal ref="viewFileModal"></view-file-modal>
      <erp-omc-tender-result-unit-modal :formDisabled="formDisabled" :formDisabledEdit="formDisabledEdit" :isWinTheBid="isWinTheBid" ref="resultUnitList" @ok="modalFormOk"></erp-omc-tender-result-unit-modal>
    </j-form-container>
    <a-row :gutter="48" v-if="formBpm">
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" :style="{ marginRight: '10px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm">提 交</a-button>
      </a-col>
    </a-row>
    <ErpOmcTenderResultFormBpmNode1Print v-if="formBpm" id="tenderNode1Content" class="print_style" :formData="this.model" :formDataHistory="formData"></ErpOmcTenderResultFormBpmNode1Print>
  </a-spin>
</template>

<script>
import { getAction, httpAction } from '@/api/manage'
import { viewFile } from '@/utils/util'
import moment from 'moment';
import { mapGetters } from 'vuex';
import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput';
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import ViewFileModal from '@views/scy/components/ViewFileModal';
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin';
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil';
import ErpOmcTenderResultUnitModal from '@views/erp/omc/tenderresult/modules/ErpOmcTenderResultUnitModal';
import AddressChoice from '@/components/AddressChoice/AddressChoice';
import SelectUserByDep from '@/views/scy/components/SelectUserByDep';
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput';
import SelectOmcProjectTenderInput from '@/views/scy/components/SelectOmcProjectTenderInput';
import CommonFlowList from '@/views/components/CommonFlowList.vue';
import Print from '@/utils/print/printarea.js';
import ErpOmcTenderResultFormBpmNode1Print from './ErpOmcTenderResultFormBpmNode1Print' // 打印
export default {
  name: 'ErpOmcTenderResultForm',
  mixins: [DisabledAuthFilterMixin, viewFile],
  components: {
    ErpOmcTenderResultUnitModal,
    SelectCustomerInput,
    SelectTeamInput,
    ViewFileModal,
    AddressChoice,
    SelectUserByDep,
    SelectCompanyInput,
    SelectOmcProjectTenderInput,
    CommonFlowList,
    ErpOmcTenderResultFormBpmNode1Print
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      confirmLoading: false,
      // 子表是否已有中标
      isWinTheBid:false,
      validatorRules: {
        bpmBizTitle: [
          { required: true, message: '请输入流程名称!' },
        ],
        bidResultNo: [
          { required: true, message: '请输入投标结果编号!' }
        ],
        createTime: [
          { required: true, message: '请选择创建日期!' }
        ],
        proposer: [
          { required: true, message: '请选择经办人!' }
        ],
        tenderId: [
          { required: true, message: '请选择关联投标档案!' }
        ],
        projectName: [
          { required: true, message: '请输入项目名称!' }
        ],
        undertaker: [
          { required: true, message: '请选择项目承接人!' }
        ],
        year: [
          { required: true, message: '请选择业绩归属年度!' }
        ],
        projectAddress: [
          { required: true, message: '请选择项目地址!' }
        ],
        detailedAddress:[
          { required: true, message: '请输入项目详细地址!' }
        ],
        businessTeam: [
          { required: true, message: '请选择经营团队!' }
        ],
        bidOpeningData: [
          { required: true, message: '请选择开标时间!' }
        ],
        ownerUnit: [
          { required: true, message: '请选择业主单位!' }
        ],
        ownerLinkman: [
          { required: true, message: '请选择业主联系人!' }
        ],
        ownerTel: [
          { required: true, message: '请输入业主联系方式！' },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ],
        tenderAgent: [
          { required: true, message: '请选择招标代理机构!' }
        ],
        tenderAgentLinkman: [
          { required: true, message: '请选择招标代理联系人!' }
        ],
        tenderAgentTel: [
          { required: true, message: '请输入招标代理联系方式！' },
          { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
        ],
        biddingMethod: [
          { required: true, message: '请选择招标方式!' }
        ],
        tenderUnit: [
          { required: true, message: '请输入投标单位!' }
        ],
        controlPrice: [
          { required: false },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        bidResult: [
          { required: true, message: '请选择中标结果!' }
        ],
        complexCoefficient: [
          { required: true, message: '请输入难度系数!' }
        ],
        resultCoefficient: [
          { required: true, message: '请输入成果系数!' }
        ],
        tenderAmount: [
          { required: true, message: '请输入投标金额!' },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        agentFee: [
          { required: false },
          { pattern: /^([0]|([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ],
        bail: [
          { required: false },
          { pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
        ]
      },
      url: {
        add: '/api/erp/omc/tenderresult/erpOmcTenderResult/add',
        edit: '/api/erp/omc/tenderresult/erpOmcTenderResult/edit',
        queryById: '/api/erp/omc/tenderresult/erpOmcTenderResult/queryById',
        queryInfoAndResultUnit: '/api/erp/omc/tender/erpOmcTender/queryInfoAndResultUnit',
        queryTenderResultUnitListByResultId: '/api/erp/omc/tenderresult/erpOmcTenderResultUnit/queryTenderResultUnitListByResultId',
        generatedFormNumber: '/api/erp/base/generatedFormNumber',
        getDepartNameByIds: '/api/erpmng/sys/sysDepart/getDepartNameByIds'
      },
      loading: false,
      columns: [
        {
          title: '投标单位',
          width:100,
          align: 'center',
          dataIndex: 'tenderUnit',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['tenderUnit'], text + '')
            }
          }
        },
        {
          title: '投标金额(元)',
          width:100,
          align: 'center',
          dataIndex: 'tenderAmount'
        },
        {
          title: '中标情况',
          width:100,
          align: 'center',
          dataIndex: 'bidResult',
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['bidResult'], text + '')
            }
          }
        },
        {
          title: '说明',
          align: 'center',
          dataIndex: 'instruction',
          width: '300px'
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   width: '120px',
        //   align: 'center',
        //   scopedSlots: {
        //     filterDropdown: 'filterDropdown',
        //     filterIcon: 'filterIcon',
        //     customRender: 'action'
        //   }
        // }
      ],
      dataSource: [],
      dictOptions: {},
      customer_contacts: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0',
      unitDictCode: 'erp_company_files,file_name,id, del_flag = 0'
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    formDisabledEdit(){
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }else{
        return !this.disabled
      }
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  watch:{
    // model:{
    //   deep: true,
    //   handler(val){
    //     if(val.tenderUnit!=null){
    //       getAction(this.url.getDepartNameByIds,{userIds:val.tenderUnit}).then(res=>{
    //         this.$set(this.model,'tenderDeptName',res)
    //       })
    //     }
    //   }
    // }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData();
    this.initDictConfig();
  },
  methods: {
    clearWinTheBidInfo(){
      this.model.bidResult = null;
      this.model.tenderAmount = null;
      this.model.tenderUnit = null;
    },
    setWinTheBidInfo(unit){
      this.$set(this.model,'bidResult',unit.bidResult);
      this.$set(this.model,'tenderAmount',unit.tenderAmount);
      this.$set(this.model,'tenderUnit',unit.tenderUnit);

    },
    handleAdd() {
      this.$refs.resultUnitList.add();
      this.$refs.resultUnitList.title = '新增';
      this.$refs.resultUnitList.disableSubmit = false;
    },
    handleEdit(record) {
      // 修改子表是否修改状态
      this.refresh = true;
      //修改已中标的状态状态
      if(record.bidResult=='1'){
        this.isWinTheBid = false;
        // 需要在操作后重置isWinTheBid的状态
        this.needReset = true;
      }
      //修改已中标的状态状态
      // this.isWinTheBid = false;
      this.$refs.resultUnitList.edit(record);
      this.$refs.resultUnitList.title = '修改';
      this.$refs.resultUnitList.disableSubmit = false;
    },
    handleDelete(id) {
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == id) {
          this.dataSource.splice(i, 1);
        }
      }
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.dataSource.length; i++) {
        if (this.dataSource[i].id == data.id) {
          this.dataSource.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.dataSource.push(data);
      }
      this.loading = false;
    },
    initDictConfig() {
      // initDictOptions('erp_employee_file,name,id').then((res) => {
      //   if (res.success) {
      //     this.$set(this.dictOptions, 'projectLeading', res.result)
      //   }
      // })
      initDictOptions('erp_company_files,file_name,id ').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'tenderUnit', res.result)
        }
      })
      initDictOptions('bid_result').then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'bidResult', res.result)
        }
      })
    },
    // 业主单位
    ownerUnitChange() {
      this.customer_contacts = 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=\'' + this.model.ownerUnit + '\'';
    },
    // 业主联系人
    contactsChange(val) {
      this.$set(this.model, 'ownerLinkman', val)
      getAction('/api/erp/omc/customermanager/erpOmcCustomerManagerContact/queryById', { id: val }).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          this.$set(this.model, 'ownerTel', data.lxfs)
        }
      })
    },
    chooseTenderChange(value,row,obj) {
      this.$set(this.model,'bidOpeningData',obj.tender_end_date)
      this.$set(this.model,'undertaker',obj.undertaker)
      this.$set(this.model,'year',obj.year)
      this.$set(this.model,'tenderId',obj.id)
      this.$set(this.model, 'projectName', obj.project_name)
      this.$set(this.model, 'projectType', obj.project_type)
      this.$set(this.model,'projectAddress',obj.project_address)
      this.$set(this.model,'detailedAddress',obj.detailed_address)
      this.$set(this.model,'ownerUnit',obj.owner_unit)
      this.$set(this.model,'ownerLinkman',obj.owner_linkman)
      this.$set(this.model,'businessTeam',obj.business_team)
      this.$set(this.model,'ownerTel',obj.owner_tel)
      this.$set(this.model,'biddingMethod',obj.bidding_method)
      this.$set(this.model,'tenderContent',obj.tender_content)
      this.$set(this.model,'tenderFile',obj.tender_file)
      this.$set(this.model,'controlPrice',obj.control_price)
      // 查询投标单位
      getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId',{ id: obj.id }).then(res => {
        if(res.success){
          this.dataSource = res.result || []
        }
      })
      // getAction(this.url.queryInfoAndResultUnit, { id: row.id }).then((res) => {
      //   console.log(res);
      //   if (res.success) {
      //       this.model.projectName = res.result.projectName
      //       this.model.projectType = res.result.projectType
      //       this.model.undertaker = res.result.undertaker
      //       this.model.year = res.result.year
      //       this.model.projectAddress = res.result.projectAddress
      //       this.model.detailedAddress = res.result.detailedAddress
      //       this.model.businessTeam = res.result.businessTeam
      //       this.model.ownerUnit = res.result.ownerUnit
      //       this.model.ownerLinkman = res.result.ownerLinkman
      //       this.model.ownerTel = res.result.ownerTel
      //       this.model.biddingMethod = res.result.biddingMethod
      //       this.model.tenderContent = res.result.tenderContent
      //       this.model.tenderFile = res.result.tenderFile
      //       this.model.controlPrice = res.result.controlPrice
      //       this.model.tenderType = res.result.tenderType
      //       this.dataSource = res.result.resultUnitList;
      //       this.model.detailedAddress = res.result.detailedAddress
      //       this.model = Object.assign({}, this.model);
      //     }
      // });
    },
    ...mapGetters(['userInfo']),
    add(value) {
      this.dataSource = []
      this.edit(this.modelDefault);
      this.model.proposer = value.loginUser.empId;
      this.model.proposerDeptId = this.userInfo().deptId;
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
      this.generatedFormNumber();
    },
    generatedFormNumber() {
      getAction(this.url.generatedFormNumber, { prefix: 'TBJG', subSystemCode: '05' }).then(res => {
        if (res.success) {
          this.$set(this.model, 'bidResultNo', res.result)
        }
      })
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      if (this.model.id) {
        getAction(this.url.queryTenderResultUnitListByResultId, { id: this.model.id }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
          }
        })
      }
      this.visible = true;
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId };
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      that.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!that.model.id) {
            httpurl += that.url.add;
            method = 'post';
          } else {
            httpurl += that.url.edit;
            method = 'put';
          }
          if(that.model.tenderDeptName&&that.model.tenderDeptName!=null){
            that.model.tenderUnit = that.model.tenderDeptName;
          }
          that.model.resultUnitList = that.dataSource;
          httpAction(httpurl, that.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        } else {
          that.$emit('unButtonDisable');
        }
      })
    },
    // 关联投标档案编号修改带出数据
    tenderFinalChange(tenderFinal){
      this.$set(this.model,'bidOpeningData',tenderFinal.tenderEndDate)
      this.$set(this.model,'undertaker',tenderFinal.undertaker)
      this.$set(this.model,'year',tenderFinal.year)
      this.$set(this.model,'tenderFinalCode',tenderFinal.tenderCode)
      this.$set(this.model, 'projectName', tenderFinal.projectName)
      this.$set(this.model, 'projectType', tenderFinal.projectType)
      this.$set(this.model,'projectAddress',tenderFinal.projectAddress)
      this.$set(this.model,'detailedAddress',tenderFinal.detailedAddress)
      this.$set(this.model,'ownerUnit',tenderFinal.ownerUnit)
      this.$set(this.model,'ownerLinkman',tenderFinal.ownerLinkman)
      this.$set(this.model,'businessTeam',tenderFinal.businessTeam)
      this.$set(this.model,'ownerTel',tenderFinal.ownerTel)
      this.$set(this.model,'biddingMethod',tenderFinal.biddingMethod)
      this.$set(this.model,'tenderContent',tenderFinal.tenderContent)
      this.$set(this.model,'tenderFile',tenderFinal.tenderFile)
      this.$set(this.model,'controlPrice',tenderFinal.controlPrice)
      // BUG#3276
      this.$set(this.model,'projectPublicity',tenderFinal.projectPublicity)

      //todo 迭代11 根据投标档案带出数据
      this.$set(this.model,'tenderUnit',tenderFinal.tenderUnit)

      // 查询投标单位
      getAction('/api/erp/omc/tender/erpOmcTenderUnitFinal/queryTenderListByTenderId',{ id: tenderFinal.id }).then(res => {
        if (res.success) {
          this.dataSource = res.result || []
        }
      })
      // 查询招标信息
      getAction('/api/erp/omc/tender/erpOmcTenderFinal/queryByIdContainTenderFile', { id: tenderFinal.id }).then(res => {
        if (res.success) {
          if (res.result && res.result.tenderFileFinal) {
            this.$set(this.model, 'tenderAgent', res.result.tenderFileFinal.tenderAgent || null) // 招标代理机构
            this.$set(this.model, 'tenderAgentLinkman', res.result.tenderFileFinal.tenderAgentLinkman || null) // 招标代理联系人
            this.$set(this.model, 'tenderAgentTel', res.result.tenderFileFinal.tenderAgentTel || null) // 招标代理联系方式
          }
        }
      })
    },

    // 点击打印
    onPrint () {
      let print = new Print({
        el: '#tenderNode1Content',
        popTitle: '投标结果详情 · 禾美环保',
        endCallback() {

        }
      })
    }
  }
}
</script>
<style>
  @import "../../../../../utils/print.css";
</style>